#include "../include/FireworkLinesAndInBall.h"

#include <algorithm>
#include <iterator>

#include "../include/utilities.h"

void FireworkLinesAndInBall::initFireworkParticles() {
	
	std::uniform_int_distribution<> lineCountDis(40, 120);
	std::normal_distribution<float> speedDis(10, 1);
	std::uniform_int_distribution<> lengthDis(-2, 3);
	
	uint8_t lineCount = lineCountDis(m_gen);
	float lengthBomb = 3 + lengthDis(m_gen);
	std::vector<Vector3> speedList;
	float initSpeed = 40 + speedDis(m_gen);
	for (int i = 0; i < lineCount; ++i) {
		initSpeed = 40 + speedDis(m_gen);
		Vector3 normal = getRandomNormal(-90, 90, 0, 360);
		Vector3 speed = Vector3Scale(normal, initSpeed);
		speedList.push_back(speed);
	}
	Color color = getRandomColor();
	addNewBombs(m_pos, speedList, color, lengthBomb);
	
	std::uniform_int_distribution<> alphaCountDis(10, 30);
	int alphaCountRandom = alphaCountDis(m_gen);
	std::uniform_int_distribution<> betaCountDis(10, 30);
	int betaCountRandom = betaCountDis(m_gen);
	float speedRatio = 0.7;
	float iterRatio = 0.4;
	while (isToDo(iterRatio)) {
		color = getRandomColor();
		initSpeed = initSpeed * speedRatio;
		speedList.clear();;
		std::vector<Vector3> ballPointPosList = getBallPos(m_pos, 1, alphaCountRandom, betaCountRandom);
		for (Vector3& ballPointPos : ballPointPosList) {
			Vector3 direction = Vector3Normalize(Vector3Subtract(ballPointPos, m_pos));
			Vector3 speed = Vector3Scale(direction, initSpeed);
			speedList.push_back(speed);
		}
		addNewBombs(m_pos, speedList, color, lengthBomb);
	}
}
